{layout name="../common/master"/}
<div id="right">
       <h4 style="border-bottom: 1px solid #ccc;padding-bottom: 3px">所有借款列表</h4>

    <form action="" method="get" role="form">
        <div class="form-group">
            <label for="">用户电话：</label>
            <input name="userPhone" {if condition="isset($_GET['userPhone'])"} value="{$_GET['userPhone']}" {/if} type="text"/>

            <label for="">逾期天数：</label>
            <input name="dueDay" {if condition="isset($_GET['dueDay'])"}  value="{$_GET['dueDay']}" {/if} type="text"/>

        </div>
        <button type="submit" class="btn btn-primary">查询</button>
    </form>
    <div>
    <button id="extend" type="submit" class="btn btn-info">导出到EXCEL</button>
    <button id="sms" type="submit" class="btn btn-primary">发送催款短信</button>
    <button id="app" type="submit" class="btn btn-danger">发送催款推送</button>
        <button id="voice" type="submit" class="btn btn-success">发送语音推送</button>
</div>
    <table class="table-bordered table  table-hover" style="margin-top: 20px;">
        <thead>
        <tr>
            <!--<th>ID</th>-->
            <th>userID</th>
            <th>打款日期</th>
            <th>还款日期</th>
            <th>用户电话</th>
            <th>实际借款金额</th>
            <th>借款期限</th>
            <th>总计还款</th>
            <th>逾期天数</th>
            <th>逾期费用</th>
            <th>现在还款</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach name="data" item="vo" key="k"}
            <tr>
                <th>{$vo['userID']}</th>
                <th>{:date("Y-m-d H:i:s",$vo['loanArrangedTime']/1000)}</th>
                <th>{$vo['repayDate']}</th>
                <th>{$vo['userPhone']}</th>
                <th>{$vo['actualAmount']}</th>
                <th>{$vo['loanRepayPeriod']}</th>
                <th>{$vo['totalRepay']}</th>
                <th>{$vo['dueDay']}</th>
                <th>{$vo['duefee']}</th>
                <th>{$vo['duefee'] + $vo['totalRepay']}</th>
                <th>
                    <div class="btn-group">
                        <a style="margin-left: 5px" href="{:URL('home/Userloan/userLoanInfo',['uid'=>$vo['id'],'type'=>1])}" class="btn btn-primary btn-sm">查看详情</a>
                    </div>
                </th>
            </tr>
        {/foreach}
        </tbody>
    </table>

</div>
<script>
    $("#extend").click(function () {
        var url="{:URL('home/Due/dueList',$_GET)}";
        url=url+"&extend=1";
        location.href=url;
    })
    $("#sms").click(function () {
        var html=`
        <form  action="" method="post" role="form">
                <label for="">选择短信模板</label>
             <select name="smsTmp" id="smsTmp" class="form-control">
                <option value=""> -- Select One --</option>
                {foreach name="smsTmp" item="vo" key="k"}
                <option value="{$vo['content']}" num="{$vo['tmp_num']}">{$vo['name']}</option>
               {/foreach}
             </select>
        </form>
        `;
        layer.open({
            btn:['发送'],
            title:'发送催款短信',
            area:['300px','300px'],
            content:html,
            yes:(function(){
               var smstmp=$("#smsTmp option:selected").val();
               var num=$("#smsTmp option:selected").attr('num');
                var phone={$phone};
                $.post("{:URL('home/Sms/sendSms')}",{smstmp:smstmp,phone:phone,tmp_num:num},function(res){
                    res=JSON.parse(res);
                    if(res.code ==0){
                        layer.alert(res.msg);
                    }else{
                        layer.alert(res.data);
                    }
                })
            })
        })
    })



    $("#app").click(function(){
                var html=`
                <form  action="" method="post" role="form">
                        <label for="">选择短信模板</label>
                        <select name="smsAppTmp" id="smsAppTmp" class="form-control">
                        <option value=""> -- Select One --</option>
                {foreach name="appSmsTmp" item="vo" key="k"}
            <option value="{$vo['content']}">{$vo['name']}</option>
            {/foreach}
    </select>
    </form>
    `;
    layer.open({
        btn:['推送'],
        title:'发送催款推送',
        area:['300px','300px'],
        content:html,
        yes:(function(){
            var smstmp=$("#smsAppTmp option:selected").val();
            var phone={$phone};
            $.post("{:URL('home/Sms/sendAppSms')}",{smstmp:smstmp,phone:phone},function(res){
                if(res.code ==0){
                    layer.alert(res.msg);
                }else{
                    layer.alert(res.data);
                }
            })
        })

    })
    })

    $("#voice").click(function(){
                var html=`
                <form  action="" method="post" role="form">
                        <label for="">选择语音模板</label>
                        <select name="smsVoiceTmp" id="smsVoiceTmp" class="form-control">
                        <option value=""> -- Select One --</option>
                {foreach name="smsVoiceTmp" item="vo" key="k"}
            <option value="{$vo['content']}">{$vo['name']}</option>
            {/foreach}
    </select>
    </form>
    `;
    layer.open({
        btn:['推送'],
        title:'发送催款推送',
        area:['300px','300px'],
        content:html,
        yes:(function(){
            var smstmp=$("#smsVoiceTmp option:selected").val();
            var phone={$phone};
            $.post("{:URL('home/Sms/sendVoice')}",{smstmp:smstmp,phone:phone},function(res){
                if(res.code ==  0){
                    layer.alert(res.msg);
                }else{
                    layer.alert(res.data);
                }
            })
        })

    })
    })
</script>
<script type="text/javascript" src="__PUBLIC__/home/tuo/DatePicker/WdatePicker.js"></script>
